package com.haoshuang.zhouzhoubang.ui.page.home.settings.skill.add

import com.haoshuang.zhouzhoubang.databinding.ItemAddSkillRightBinding
import com.haoshuang.zhouzhoubang.model.bean.SkillAddBean
import com.mufeng.libs.base.BaseBindingHolder
import com.mufeng.libs.base.BaseBindingQuickAdapter
import com.mufeng.libs.core.setOnItemClick
import com.mufeng.libs.utils.view.click
import com.mufeng.libs.utils.view.flexbox
import com.mufeng.libs.utils.view.removeAllAnimation


/**
 * 
 */
class AddSkillRightAdapter(data: MutableList<SkillAddBean.Small>) : BaseBindingQuickAdapter<SkillAddBean.Small, ItemAddSkillRightBinding>(data) {

    // 可以选中
    var type = 1

    override fun onBindViewHolder(holder: BaseBindingHolder, position: Int, item: SkillAddBean.Small?) {
        holder.getViewBinding<ItemAddSkillRightBinding>().apply {
            tvCateName.text = item?.cate_name
            val data = item?.little_cate?: mutableListOf()
            val adapter = AddSkillLabelAdapter(data)
            recyclerView.flexbox()
            recyclerView.adapter = adapter
            recyclerView.removeAllAnimation()
            adapter.setOnItemClick { view, positionLabel, itemLabel ->
//                if (type == 2) return@setOnItemClick
                itemLabel?.is_checked = itemLabel?.is_checked != true
                adapter.notifyItemChanged(positionLabel)
                val list = adapter.items.filter { it.is_checked != true }
                item?.is_checked = list.isEmpty()
                notifyItemChanged(position)
            }
            ivAll.isSelected = item?.is_checked == true
            llAll.click {
                if (item?.is_checked == true){
                    // 全选 -> 不全选
                    item.is_checked = false
                    data.forEach { it.is_checked = false }
                    adapter.notifyDataSetChanged()
                    notifyItemChanged(position)
                }else{
                    // 不全选 -> 全选
                    item?.is_checked = true
                    data.forEach { it.is_checked = true }
                    adapter.notifyDataSetChanged()
                    notifyItemChanged(position)
                }
            }
        }
    }
}